﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Share/Index.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" language="JavaScript">
    var WebInfomationPublish = { Wi_id: 0, Wi_title0: "", Wi_title1: "", Wi_content: "", Wi_template: 14, Wi_recommend: 0, Wi_state: 1, Wi_startTime: new Date(), Wi_endTime: new Date() };
    var mylist;
    var regular_input = {
        Wi_title0: { exp: /^.{1,200}$/, m: "请输入标题，200个字符以内" },
        Wi_recommend: { exp: /^[0-9]\d*$/, m: "只能输入整数" }
    }
    var mainForm = "";
    $(document).ready(function () {
        mylist = new TurnPage("mylist");
        mylist.pageSize = 8;
        mylist.callback = function () { ajax(); };

        function ajax() {
            var param = { pagesize: mylist.pageSize, pageno: mylist.currPage, template: 14 };
            $.post("/web/getlist.html?" + (new Date()).getTime(), param, function (data) {
                data = $.evalJSON(data);
                if (mylist.currPage == 1) {
                    mylist.total = $.grep(data, function (n, i) { return typeof (n.total) == "number"; })[0].total;
                    data = $.grep(data, function (n, i) { return typeof (n.total) == "undefined"; });
                }
                loadDta(data);
            });
        }

        var loadDta = function (list) {
            var sp = [];
            $("#mainTable tbody[name=mainlist]").html("");
            $.each(list, function (i, n) {
                sp.push('<tr>');
                sp.push('<td>' + n.Wi_title1 + '</td>');
                sp.push('<td><a href="#mainForm" onclick="edit(' + n.Wi_id + ')" name="linkEdit" >修改</a>  <a href="#" onclick="del(' + n.Wi_id + ')" name="linkDel" >删除</a></td>');
                sp.push('</tr>');
            });
            $("#mainTable tbody[name=mainlist]").append(sp.join(''));
            //if (sp.length == 0) alert('没有符合条件的数据');
            $("#pager").html(mylist.getOutput());
        }
        $("input[name=buttSeek]").click(function () {
            mylist.currPage = 1;
            ajax();
        });
        $("input[name=buttReset]").click(function () {
            $("input[name=Wi_title0]").val('');
            $("input[name=Wi_title1]").val('');
            $("#Wi_content_ifr").contents().find("#tinymce").html("");
            $("input[name=Wi_recommend]").val('0');
            $("input[name=buttsend]").val('保存');
        });

        //
        $("input[name=buttsend]").click(function () {
            if (!$.checkFormValid("mainForm")) return false;
            $.fillObj(WebInfomationPublish, "#mainForm");
            WebInfomationPublish.Wi_content = tinyMCE.get('Wi_content').getContent();
            if (WebInfomationPublish.i_content == '') {
                alert("请输入内容"); return false;
            }
            $.post("/web/saveInfomationPublish.html", { WebInfomationPublish: $.toJSON(WebInfomationPublish) }, function (dta) {
                alert("保存成功");
                window.parent.frames["rightFrame"].location.reload();
                ajax();
            });
        });
        ajax();
    });
    function edit(id) {
        $.post("/web/getinfomationbyid.html?" + (new Date()).getTime(), { res: id }, function (dta) {
            WebInfomationPublish = $.evalJSON(dta);
            $.fillForm(WebInfomationPublish, "#mainForm");
            $("#Wi_content_ifr").contents().find("#tinymce").html(WebInfomationPublish.Wi_content);
        });
        $("input[name=buttsend]").val('修改');
    }
    function del(id) {
        if (confirm("确定删除?")) {
            $.post("/web/deleteinfomation.html?" + (new Date()).getTime(), { res: id }, function (dta) {
                alert("删除成功");
                $("input[name='buttSeek']").click();
            });
        }
    }
</script>
    <table cellspacing="0" id="seekForm">
        <tr>
            <th>
                学习资源_教辅资料管理
            </th>
        </tr>
        <tr>
        <td>
            <input type="button" name="buttSeek" value="查询" onclick="" class="btn1" />
        </td>
        </tr>
    </table>
    <table id="mainTable" cellspacing="0">
        <caption style="color: red; font-size: 15px; font-weight: bold">列表</caption>
        <tr>
            <th>
                标题
            </th>
            <th>
            </th>
            </tr>
        <tbody name="mainlist">
        
        </tbody>
    </table>
    <div id="pager" class="pager">
    </div>
    <table cellspacing="0" id="mainForm">
        <tr>
            <th colspan="3">
                编辑
            </th>
        </tr>
        <tr>
            <td>正文标题</td>
            <td><input id="Wi_title0" name="Wi_title1" maxlength="200"  /></td>
            <td><span class="tsxx"></span></td>
        </tr>
                 <tr>
            <td>正文内容</td>
            <td><% Html.RenderPartial("~/Views/Plugins/TinymceAreaText.ascx", (ViewData["tinymceId"] = "Wi_content"));%></td>
            <td><span class="tsxx"></span></td>
        </tr>   
        <tr>
            <td>排序规则</td>
            <td><input id="Wi_recommend" name="Wi_recommend" value="0"/>数字越大排在越前面</td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
            <td>生效时间</td>
            <td><input id="Wi_startTime" class="time" name="Wi_startTime" value="<%=System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") %>" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
            <td>失效时间</td>
            <td><input id="Wi_endTime" class="time"  name="Wi_endTime" value="<%=System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") %>" /></td>
            <td><span class="tsxx"></span></td>
        </tr>

        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttsend" class="btn1" style="width: 200px" 
                    value="新增" />
                <input type="button" name="buttReset" class="btn1" style="width: 200px" value="重置" />
            </td>
        </tr>
    </table>
</asp:Content>
